Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

r18gs

Package Overview
Dependencies
Maintainers
0
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

r18gs

A simple yet elegant, light weight, react18 global store to replace Zustand for better tree shaking.

  • 2.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4.8K
increased by19.91%
Maintainers
0
Weekly downloads
 
Created
Source

React18GlobalStore

Test Maintainability Code Coverage Version Downloads Bundle Size Gitpod Ready

🌐 Live Demo with Code: https://r18gs.vercel.app/

Motivation

While developing libraries utilizing React 18 features with Zustand, I encountered issues with tree-shaking when importing from specific folders. This caused the creation of multiple Zustand stores, resulting in bugs and unnecessary JavaScript code execution.

To address this, I created a lightweight, minimalistic store designed for shared states that optimizes tree-shaking and supports component imports from separate files.

Features

Full TypeScript Support
Unlock the Full Power of React18 Server Components
Compatible with All React18 Build Systems and Frameworks
Comprehensive Documentation with Typedoc
Examples for Next.js, Vite, and Remix
Seamlessly Works with Selectors

Simple Global State Across Components

Use the useRGS hook just like useState, but with a unique key to make the state accessible across components.

const [state, setState] = useRGS<number>("counter", 1);

Or initialize using a function:

const [state, setState] = useRGS<number>("counter", () => 1);

🔗 Getting Started: Guide

What's New?

🚀 Now Supports Selectors for Complex Stores
Explore more at https://r18gs.vercel.app/.

Using Plugins

Extend the store's functionality with the create function, withPlugins function, or the useRGSWithPlugins hook. Features like persistence to local storage can be easily integrated.

// store.ts
import { create } from "r18gs/dist/with-plugins";
import { persist } from "r18gs/dist/plugins"; // Use third-party or custom plugins

export const useMyPersistentCounterStore = create<number>("persistent-counter", 0, [persist()]);

Use it just like useState without needing an initial value:

const [persistedCount, setPersistedCount] = useMyPersistentCounterStore();

🔗 Learn More: Leveraging Plugins

Contributing

Contributions are welcome! See contributing.md.

🌟 Don't Forget to Star this repository!

Hands-On Learning Resources

Repo Stats

License

This library is licensed under the MPL-2.0 open-source license.

Support our work by sponsoring or enrolling in our courses.


Made with 💖 by Mayank Kumar Chaudhari

Keywords

FAQs

Package last updated on 17 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc